package org.mybatis.example;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author zhouchaoqun
 * @date 2018/10/18 下午4:58
 */
public class Main {
    public static void main(String[] args) throws IOException {
        String resource = "mybatis.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

        SqlSession session = sqlSessionFactory.openSession();
        try {
            Blog blog = session.selectOne("org.mybatis.example.BlogMapper.selectById", 3);
            System.out.println(blog);
            blog = session.selectOne("org.mybatis.example.BlogMapper.selectById", 2);
            System.out.println(blog);
            blog = session.selectOne("org.mybatis.example.BlogMapper.selectById", 3);
            System.out.println(blog);
        } finally {
            session.close();
        }
    }
}
